//Flies sideways and aims walls

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let SEshotm2=("script\SoundEffects\shotm2.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=6;
let scale=0.75;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let type=GetArgument;
let direction=rand_int(0,1);

if(startx<cx){ SetAngle(0); }
if(startx>cx){ SetAngle(180); }
SetSpeed(rand(5,6.5));

@Initialize{
	LoadGraphic("\script\Images\Enemies\Ghosts.png");
	LoadSE("script\SoundEffects\shotm2.wav");
	LoadSE("script\SoundEffects\shotb1.wav");

	SetInvincibility(35);
	SetLife(15);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
if(type==1){
	if(time==60){
	let angle=0;
		loop(5){
		let dir=-2;
			loop(6){
			CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+angle+dir,27,0);
			dir+=4/5;
			}
		angle+=360/5;
		}
	PlaySE(SEshotm2);
	}
} //Type 1
if(type==2){
	if(time==60){
	let angle=360/8;
		loop(4){
		let dir=-10;
			loop(4){
			CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+angle+dir,44,0);
			dir+=20/3;
			}
		angle+=360/4;
		}
	PlaySE(SEshotb1);
	}
} //Type 2
} //Easy

if(GetCommonData("Difficulty")==2){
if(type==1){
	if(time==60){
	let angle=0;
		loop(5){
		let dir=-4;
			loop(8){
			CreateShot01(GetX,GetY,3,GetAngleToPlayer+angle+dir,27,0);
			dir+=8/7;
			}
		angle+=360/5;
		}
	PlaySE(SEshotm2);
	}
} //Type 1
if(type==2){
	if(time==60){
	let angle=360/10;
		loop(5){
		let dir=-12;
			loop(5){
			CreateShot01(GetX,GetY,3,GetAngleToPlayer+angle+dir,44,0);
			dir+=24/3;
			}
		angle+=360/5;
		}
	PlaySE(SEshotb1);
	}
} //Type 2
} //Normal

if(GetCommonData("Difficulty")==3){
if(type==1){
	if(time==60){
	let angle=0;
		loop(6){
		let dir=-5;
			loop(10){
			CreateShot01(GetX,GetY,3.5,GetAngleToPlayer+angle+dir,27,0);
			dir+=10/9;
			}
		angle+=360/6;
		}
	PlaySE(SEshotm2);
	}
} //Type 1
if(type==2){
	if(time==60){
	let angle=360/12;
		loop(6){
		let dir=-11;
			loop(5){
			CreateShot01(GetX,GetY,3.5,GetAngleToPlayer+angle+dir,44,0);
			dir+=22/4;
			}
		angle+=360/6;
		}
	PlaySE(SEshotb1);
	}
} //Type 2
} //Hard

if(GetCommonData("Difficulty")==4){
if(type==1){
	if(time==60){
	let angle=0;
		loop(6){
		let dir=-6;
			loop(10){
			CreateShot01(GetX,GetY,4,GetAngleToPlayer+angle+dir,27,0);
			dir+=12/9;
			}
		angle+=360/6;
		}
	PlaySE(SEshotm2);
	}
} //Type 1
if(type==2){
	if(time==60){
	let angle=360/12;
		loop(6){
		let dir=-14;
			loop(5){
			CreateShot01(GetX,GetY,4,GetAngleToPlayer+angle+dir,44,0);
			dir+=28/4;
			}
		angle+=360/6;
		}
	PlaySE(SEshotb1);
	}
} //Type 2
} //Lunatic
} //Onscreen


if(GetSpeed>-0.3 && time<90){ SetSpeed(GetSpeed-0.1); }
if(time>=90){
	SetSpeed(GetSpeed-0.06);
	if(startx<cx){ SetAngle(GetAngle+0.8); }
	if(startx>cx){ SetAngle(GetAngle-0.8); }
}


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
	SetTexture(GRenemy);
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(0,151,44,210); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(44,151,87,210); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(88,151,132,210); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(133,151,176,210); }
		if(animation>=ani*4 && animation<ani*5){ SetGraphicRect(177,151,220,210); }
		if(animation>=ani*5 && animation<ani*6){ SetGraphicRect(221,151,264,210); }
		if(animation>=ani*6 && animation<ani*7){ SetGraphicRect(265,151,308,210); }
	SetGraphicAngle(0,0,0);
	if(type==1){ SetColor(255,255,50); }
	if(type==2){ SetColor(50,50,255); }
	SetGraphicScale(1,1);
	SetRenderState(ADD);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(2){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	loop(3){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}